package gms.dao.match;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Property;
import org.springframework.orm.hibernate4.support.HibernateDaoSupport;


import gms.entities.match.MatchInfo;

public class MatchInfoDaoImp extends HibernateDaoSupport implements MatchInfoDao{

	@Override
	public void queryByTime(MatchInfo matchInfo) {
		System.out.println("queryByTime.........");

		
	}

	@Override
	public void queryByAttr(MatchInfo matchInfo) {
		// TODO Auto-generated method stub
		System.out.println("queryByAttr.........");
		List<MatchInfo> list = this.getHibernateTemplate().findByExample(matchInfo);
		for (MatchInfo m : list) {
			System.out.println(m.toString());
		}
	}
	
	/**
	 * 查找总记录数
	 */
	@Override
	public int findCount() {
		String hql = "select count(*) from MatchInfo";
		List<Long> list = (List<Long>) this.getHibernateTemplate().find(hql);
		if(list.size() > 0){
			return list.get(0).intValue();
		}
		return 0;
	}

	/**
	 * 分页查找赛事信息表
	 */
	@Override
	public List<MatchInfo> findByPage(int begin, int pageSize) {
		DetachedCriteria criteria = DetachedCriteria.forClass(MatchInfo.class);
		criteria.addOrder(Property.forName("startTime").asc());
		List<MatchInfo> list = 	(List<MatchInfo>) this.getHibernateTemplate().findByCriteria(criteria, begin, pageSize);
		for (MatchInfo m : list) {
			System.out.println(m.toString());
		}
		return list;
	}

	/**
	 * 根据ID查询赛事信息表
	 */
	@Override
	public MatchInfo findByID(int matchInfoID) {
		return this.getHibernateTemplate().get(MatchInfo.class, matchInfoID);
	}

	/**
	 * 更新赛事信息表
	 */
	@Override
	public void update(MatchInfo matchInfo) {
		this.getHibernateTemplate().update(matchInfo);
	}
	
	@Override
	public void delete(MatchInfo matchInfo) {
		this.getHibernateTemplate().delete(matchInfo);
	}
}
